package com.zeny.online.job;

import com.zeny.online.service.UsersService;
import com.zeny.online.util.QiniuUtils;
import com.zeny.online.util.RedisUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Set;

/**
 * @ClassName CleanImgJob
 * @Description 定时清理垃圾照片
 * @Author zeny
 */
public class CleanImgJob implements Job {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private UsersService usersService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Set<Object> img = redisUtil.sGet("clean_img");
        img.forEach(i -> {
            String myImg = (String) i;
            if (!"face-default-cat.png".equals(myImg)) {
                QiniuUtils.deleteFileFromQiniu(myImg);
            }
        });
        redisUtil.del("clean_img");
    }
}
